# Author:: Alexandre Ribeiro de Souza (<alexandre@lumis.com.br>)

tag("client_#{Chef::Config[:node_name].split('-')[1]}")

user = node['authorization']['system']['user']

# find all members of the user group, so we can make them members
group_members = Array.new
group_members << user

search(:users, "groups:#{user}").each do |u|
  group_members << u.id
end

# create user
group user do
  # find all users that currently exist on the machine then only add those
  # group_members that already have user accounts
  local_users = Array.new
  node['etc']['passwd'].each do |name, values|
    local_users << name
  end
  gid 2000
  group_members = group_members & local_users
  members group_members
end

user user do
  comment "Lumis System User"
  uid 2000
  gid user
  home "/home/#{user}"
  system true
  supports :manage_home => true
  shell "/sbin/nologin"
end
